<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>业务数据模板编辑模板</title>
    <#include "/pubHeadStyle.html">
    <script src="${ctx}/formStatic/script/InitMirror.js"></script>
    <script src="${ctx}/formStatic/script/codemirror.js"></script>
</head>
<body>
<div class="layui-form-item">
        <div class="layui-footer" style="padding:20px 20px 0 20px">
            <button class="layui-btn layui-btn-sm" id="save" lay-submit="" lay-filter="save">
                保存
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" id="return" >
                取消
            </button>
        </div>
</div>
<div class="layui-form-item" style="padding:0 20px 20px 20px">
    <form id="bpmDataTemplateForm" method="post" >
        <table class="table-detail">
            <tr>
                <th width="5%" nowrap="nowrap">模板</th>
                <td colspan="3">
                    <textarea id="templateHtml" name="templateHtml" style="width: 99%;height: 700px;overflow-y: auto;"></textarea>
                </td>
            </tr>
        </table>
        <input name="id" type="hidden" id="dataTemplateId" />
    </form>
</div>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'form', 'jquery','setter'], function () {
        var form = layui.form;
        var $ = layui.$;
        var setter = layui.setter;
        var formKey = '${formKey}' || '';
        $.ajax({
            url: serverPath.formPath + setter.formLinkPath +"dataTemplate/editTemplate?formKey="+formKey,
            type: "get",
            contentType: 'application/json',
            dataType: 'json',
            success: function (data) {
                var dataTemplate=data.data;
                $("#templateHtml").val(dataTemplate.templateHtml);
                $("#dataTemplateId").val(dataTemplate.id);
            }
        });
        $("#return").on('click',function(){
            window.close();
        });

        // 保存
        form.on('submit(save)', function (data) {
            var templateHtml = $('#templateHtml').val();
            var templateId = $('#dataTemplateId').val();
            $.ajax({
                url: serverPath.formPath + setter.formLinkPath +"dataTemplate/saveTemplate",
                type: "POST",
                data:{id:templateId,templateHtml:encodeURIComponent(templateHtml)},
                dataType: 'json',
                success: function (result) {
                    window.parent.layer.alert(result.msg, function () {
                        window.close();
                    });
                }
            })
        });
    });
</script>
</body>
</html>